﻿#include "funclistitem.h"
#include "ui_funclistitem.h"
#include <QPixmap>

// 类外初始化静态成员变量
int FuncListItem::m_classId = 0;

FuncListItem::FuncListItem(QString iconPath ,QString funcName,const QListWidget* listWidget, QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::FuncListItem)
    , itemId(m_classId++)
{
    ui->setupUi(this);
    QPixmap icon(iconPath);
    icon.scaled(ui->lb_FuncIcon->size(), Qt::KeepAspectRatio);
    ui->lb_FuncIcon->setScaledContents(true);
    ui->lb_FuncIcon->setPixmap(icon);
    ui->lb_FuncText->setText(funcName);

    connect(listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(slot_Selected(int)));
}

FuncListItem::~FuncListItem()
{
    delete ui;
}

void FuncListItem::slot_Selected(int currentId)
{
    QPixmap iconSelected(":/img/VerticalBars.png");
    iconSelected.scaled(ui->lb_FuncIconSelected->size(), Qt::KeepAspectRatio);
    ui->lb_FuncIconSelected->setScaledContents(true);

    if (currentId == itemId){
        ui->lb_FuncIconSelected->setPixmap(iconSelected);
    }else{
        ui->lb_FuncIconSelected->clear();
    }
}
